local DIY = require "packages.diy_utility.diy_utility"

local skel = fk.CreateSkill {
  name = "rmt__huayan",
  tags = {DIY.ReadySkill},
}

Fk:loadTranslationTable{
  ["rmt__huayan"] = "化焱",
  [":rmt__huayan"] = "<a href='diy_ready_skill'>蓄势技</a>，当你对一名角色第二次造成火焰伤害时，你可以弃置所有牌，令此伤害+3，"..
  "若如此做，此后算起的第四轮结束时，若你未重置此技能，你阵亡。",
  ["#rmt__huayan-invoke"] = "化焱：你可以弃置所有牌，令 %dest 受到的伤害+3！",
  ["@rmt__huayan"] = "化焱:倒计时",

  ["$rmt__huayan1"] = "南岳干、钟山铜，应机方获隼。",
  ["$rmt__huayan2"] = "丙丁火、藏乎兑，此兆一线生。",
}

skel:addEffect(fk.DamageCaused, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name) and data.damageType == fk.FireDamage and not data.to.dead and not player:isNude()
      and data.from == player and
      #player.room.logic:getActualDamageEvents(2, function (e)
        local damage = e.data
        return damage.damageType == fk.FireDamage and damage.from == player and damage.to == data.to
      end, Player.HistoryGame, 1) == 1
  end,
  on_cost = function(self, event, target, player, data)
    if player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#rmt__huayan-invoke::"..data.to.id }) then
      event:setCostData(self, {tos = {data.to }})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data:changeDamage(3)
    room:setPlayerMark(player, "@rmt__huayan", 4)
    player:throwAllCards("he")
  end,
})

skel:addEffect(DIY.SkillReadyFinish, {
  can_refresh = function(self, event, target, player, data)
    return target == player and data.skill.name == skel.name
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@rmt__huayan", 0)
  end,
})

skel:addEffect(fk.RoundEnd, {
  anim_type = "negative",
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@rmt__huayan") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:removePlayerMark(player, "@rmt__huayan", 1)
    if player:getMark("@rmt__huayan") == 0 then
      room:killPlayer({who = player})
    end
  end,
})

return skel
